/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.zf.platform.controller;

import com.zf.platform.entity.User;
import com.zf.platform.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;

/**
 *
 *@author : sunzb(sunzb@hsit.com.cn)
 *@date: 2019/1/7
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

    @Autowired
    UserRepository userRepository;

    @GetMapping(path = "info")
    public User get(String id) {
        return userRepository.findById(id).get();
    }

    @PostMapping(path = "add")
    public User add(User user) {
        return userRepository.save(user);
    }

    @PostMapping(path = "login")
    public User login(@RequestBody User user) {
        return userRepository.getByUsernameAndPassword(user.getUsername(), user.getPassword());
    }
}
